package com.deep.sso.client.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

/**
 * 单点登录客户端
 *
 * @author Deep
 * @date 2022/2/8
 */
@Controller
public class ClientController {
    @ResponseBody
    @GetMapping("/")
    public String clientHello() {
        return "client hello";
    }


    @GetMapping(value = "/employees")
    public String employees(Model model, HttpSession session, @RequestParam(name = "token", required = false) String token) {

        Object loginUser = session.getAttribute("loginUser");
        if (loginUser == null && token == null) {
            //没登录,跳转到服务器登录
            return "redirect:http://ssoserver.com:8080/login.html?redirect_url=http://ssoclient1.com:8081/employees";
        } else {
            List<String> emps = new ArrayList<>();
            emps.add("张三");
            emps.add("李四");
            model.addAttribute("emps", emps);
            return "employees";
        }
    }
}
